package 多线程.CountDownLatch;

import java.util.concurrent.CountDownLatch;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);//添加线程数

        for(int i = 1;i<=10;i++){//创建10个线程
            int id = i;//
            Thread t1 = new Thread(() -> {
                System.out.println("线程启动"+id);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("贤臣结束"+id);
                latch.countDown();
            });
            t1.start();
        }
        latch.await();//等待所有线程
        System.out.println("所有线程结束");
    }
}
